import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";

import AutoImport from "unplugin-auto-import/vite";
import svgLoader from "vite-svg-loader";
import path from "path";
console.log(path, __dirname, path.resolve(__dirname, "./src"));
// https://vitejs.dev/config/

export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), "");
  return {
    server: {
      port: 8888,
      // 跨域处理
      proxy: {
        "^/api": {
          target: env.VITE_HOST_URL,
          // target: "http://localhost:2703",
          changeOrigin: true,
          // rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
    plugins: [
      vue(),
      svgLoader(),
      AutoImport({
        imports: ["vue", "vue-router", "pinia"],
      }),
      Components({
        resolvers: [
          AntDesignVueResolver({
            importStyle: false, // css in js
          }),
        ],
      }),
    ],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
      },
      extensions: [".js", ".vue"],
    },
  };
});

// export default
// defineConfig({
//   server: {
//     port: 8888,
//     // 跨域处理
//     proxy: {
//       "^/api": {
//         target: "http://localhost:2703",
//         changeOrigin: true,
//         // rewrite: (path) => path.replace(/^\/api/, ""),
//       },
//     },
//   },
//   plugins: [
//     vue(),
//     svgLoader(),
//     AutoImport({
//       imports: ["vue", "vue-router", "pinia"],
//     }),
//     Components({
//       resolvers: [
//         AntDesignVueResolver({
//           importStyle: false, // css in js
//         }),
//       ],
//     }),
//   ],
//   resolve: {
//     alias: {
//       "@": path.resolve(__dirname, "./src"),
//     },
//     extensions: [".js", ".vue"],
//   },
// });
